//
//  CommentTableCell.m
//  CommonFrame
//
//  Created by Bang-guo on 15/7/21.
//  Copyright (c) 2015年 guobang. All rights reserved.
//

#import "CommentTableCell.h"

@implementation CommentTableCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        if ([reuseIdentifier isEqualToString:@"cell"]) {
            
            [self createSubViews];
            
        }
        if ([reuseIdentifier isEqualToString:@"cell1"]) {
            
            [self createSubViews1];
        }
        
    }
    
    return self;
}

-(void)createSubViews {

//    UIImageView *imageV = [[[UIImageView alloc] init]autorelease];
//    imageV.backgroundColor = [UIColor redColor];
//    [self addSubview:imageV];
//    imageV.frame =CGRectMake(20 + i % 3 * (100 + 23), (210 + i / 3 * (80 + 30)), 80, 80);
    
}

-(void)createSubViews1 {
    
    self.commentImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 25, 50, 50)];
    self.commentImage.layer.masksToBounds = YES;
    self.commentImage.layer.cornerRadius = 25;
    [self.contentView addSubview:self.commentImage];
    
    self.commentNameL = [[BaseLabel alloc] initWithFrame:CGRectMake(65, 5, WIDTH - 70, 90)];
    [self.contentView addSubview:self.commentNameL];
    self.commentNameL.numberOfLines = 0;
    

    
    
}

-(void)setRecArray:(NSMutableArray *)recArray {
    
    if (_recArray != recArray) {
        
        _recArray = recArray;
    }
    
    for (int i = 0; i < recArray.count; i++) {
        
        UIImageView *imageV = [[UIImageView alloc] init];
        imageV.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:imageV];
        imageV.frame =CGRectMake(5 + i * 54, 5, 40, 40);
        imageV.layer.masksToBounds = YES;
        imageV.layer.cornerRadius = 20;
        Comment *com = recArray[i];
        [imageV sd_setImageWithURL:[NSURL URLWithString:com.avatar_s] placeholderImage:[UIImage imageNamed:@"icon1024.png"]];
        
    }
    
}

-(void)setComment:(Comment *)comment {
    
    if (_comment != comment) {
        _comment = comment;
    }
    
    [self.commentImage sd_setImageWithURL:[NSURL URLWithString:comment.userAvatar_s]];
    
    
    
    NSString *str = [NSString stringWithFormat:@"%@: %@", comment.userName, comment.userComment];
    
    NSString *stringTobeloved= [NSString stringWithFormat:@"%@", str];
    NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc]initWithString:stringTobeloved];
    NSRange redRange1 = NSMakeRange(0, [NSString stringWithFormat:@"%@", comment.userName].length);
    [attributedString1 addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:redRange1];
    
    
    [self.commentNameL setAttributedText:attributedString1];
    
    
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
